package zj.xinxin.business.business.articale.converter;

import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import zj.xinxin.api.moudle.article.dto.CategoryDto;
import zj.xinxin.api.moudle.article.entity.CategoryEntity;
import zj.xinxin.api.moudle.article.vo.CategoryVo;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.Date;

/**
 * @author junzhou
 * @date 2022/4/13 10:51
 * @since 1.8
 */
@Mapper(componentModel = "spring")
public interface CategoryConverter {

    CategoryConverter INSTANCE = Mappers.getMapper(CategoryConverter.class);

    CategoryEntity toEntity(CategoryVo category);

    CategoryDto toDto(CategoryEntity entity);

    default LocalDateTime toLocalDateTime(Date date) {
        if (date == null){
            return null;
        }
        return LocalDateTime.ofInstant(date.toInstant(), ZoneId.of("Asia/Shanghai"));
    }
}
